<template>
    <div>
      <FormPanel
        ref="from"
        :list="formList"
        :cols="1"
        @formChange="changeHandle"
        :isSubmitBtn="false"
        labelWidth="80" />
      <BreakSpace label="处理明细" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="table"
        height="auto"
        :isColumnFilter="false"
        :isPagination="false"
        :isToperInfo="false"
        :columns="columns"
        :params="fetchParams"
        :dataSource="ccontroldealwithlist"
        :isSelectColumn="false"
        columnsRef="jzySeries"
        :onColumnsChange="columns => this.columns = columns"
      />
      <div class="dialogBottmView" >
        <el-button @click="closeDrawer(1)">关 闭</el-button>
        <el-button @click="closeDrawer(2)" type="primary">确 定</el-button>
      </div>
    </div>
</template>

<script>
  const iscontrolCar = [
    {text: '是', value: 'Y'},
    {text: '否', value: 'N'},
  ]
  // 单据状态（A:未确认，B:已确认，C：未控车，D：已控车,E:处理中,F:关闭）
  const statusBill=[
    {text: '未确认', value: 'A'},
    {text: '已确认', value: 'B'},
    {text: '未控车', value: 'C'},
    {text: '已控车', value: 'D'},
    {text: '处理中', value: 'E'},
    {text: '关闭', value: 'F'},
  ]
  import { getdealwithlist } from '@/api/customerService/arbitration/index';
  export default {
    props: {
      type: {
        type: String,
        default: 'add'
      },
      rowData: {
        type: Object,
        default: () => ({})
      }
    },
    name: 'controlcar',
    data() {
      this.saveData=null;
      return{
        fetchParams:{id:''},
        columns: this.createTableColumns(),
        ccontroldealwithlist:[],
        formList: this.createTopFilterList(),
      };
    },
    created() {
      this.fetchParams.id=this.rowData.id
      getdealwithlist(this.fetchParams).then(res=>{
         this.ccontroldealwithlist=res.data.records
      })
    },
    methods:{
      //  处理明细列表
      createTableColumns(){
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '工单号',
            dataIndex: 'workOrderNo',
            sorter: true,
          },
          {
            title: '描述',
            dataIndex: 'remarks',
            sorter: true,
          },
          {
            title: '状态',
            dataIndex: 'statusBill',
            dictItems:statusBill,
            sorter: true,
          },
          {
            title: '操作日期',
            dataIndex: 'createdAt',
            dateFormat:'yyyy-MM-dd HH:mm:ss',
            sorter: true,
          },
          {
            title: '操作人员',
            dataIndex: 'handleBy',
            sorter: true,
          }
        ]
      },
      closeDrawer(type){
        if(type==1){
          this.$emit('close')
        }else{
          const base=this.$refs.from.SUBMIT_FORM();
          if(base){
           const data= Object.assign(this.rowData,base)
            this.$emit('close',data)
          }
        }
      },
      choose(val){
        if (val && val==='N') {
          this.formList.forEach(item=>{
            if (item.fieldName == 'controlRemarks') {//销售的子类
              item.rules = [{
                required: true,
                message: '必填',
                trigger: 'change'
              }]
            }
          })
        }
      },
      createTopFilterList(){
        return[
          {//3
            type: 'SELECT',
            label: '是否控车',
            fieldName: 'iscontrolCar',
            initialValue: '',
            placeholder: '选择',
            selfCols:2,
            change:this.choose,
            itemList:iscontrolCar,
            rules : [{
              required: true,
              message: '必填',
              trigger: 'change'
            }]
          },
          {
            type: 'TEXT_AREA',
            label: '描述',
            fieldName: 'controlRemarks',
            placeholder: '',
            initialValue: '',
            rules: []
          },
        ]
      },
      changeHandle(val) {
        this.saveData=val;
      },
    }
  };
</script>

<style scoped>

</style>
